package com.fourpigeon.dao;

import com.fourpigeon.domain.BlogDeal;
import com.fourpigeon.domain.BlogPractice;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
//
/**
 * 陪教贴
 * 数据库操作
 */
@Mapper
@Repository
public interface BlogPracticeDao {
    @Select("select * from tb_blog_practice where userId = #{userId} and id < #{startId} and status < 2 order by createTime DESC limit 6")
    public List<BlogPractice> getByUserId(Long userId,Long startId);
    @Select("select * from tb_blog_practice where id = #{id} and status < 2")
    public BlogPractice getById(Long id);
    @Select("select * from tb_blog_practice where status<2")
    public List<BlogPractice> getAll();
    @Update("update tb_blog_practice set type=#{type},demand=#{demand},time=#{time},location=#{location},price=#{price},people=#{people},content=#{content},contact=#{contact},status=#{status} where id = #{id}")
    public boolean update(BlogPractice blogPractice);
    @Insert("insert into tb_blog_practice values(#{id},#{userId},#{icon},#{userName},#{type},#{demand},#{time},#{location},#{price},#{people},#{content},#{contact},#{status},#{createTime},#{updateTime})")
    public boolean save(BlogPractice blogPractice);
    @Delete("delete from tb_blog_practice where id = #{id} and status < 2")
    public boolean delete(Long id);
    @Select("select * from tb_blog_practice where id < #{start} and status < 2 order by createTime DESC,id DESC limit 6")
    public List<BlogPractice> getPractices(Long start);

    @Select("select * from tb_blog_practice where (demand like concat('%', #{searchKeyWord}, '%') or content like concat('%', #{searchKeyWord}, '%') or location like concat('%', #{searchKeyWord}, '%')) and type = #{type} and status < 2")
    public List<BlogPractice> getSearchPractices(String searchKeyWord, Short type);

    @Select("select * from tb_blog_practice where demand like concat('%', #{searchKeyWord}, '%') or content like concat('%', #{searchKeyWord}, '%') or location like concat('%', #{searchKeyWord}, '%') and status < 2")
    public List<BlogPractice> getAllSearchPractices(String searchKeyWord);

    @Select("select * from tb_blog_practice where type = #{type} and status < 2 limit 6")
    public List<BlogPractice> getByType(Short type);

    @Select("select * from tb_blog_practice where status < 2 order by createTime DESC")
    public List<BlogPractice> getHotPractice();

    @Update("update tb_blog_practice set status = 1 where id = #{id}")
    public boolean reportBlog(Long id);
}
